<!--设置模块唯一ID-->
<div id="sjs_shejishirenwu_managerConfirm">
<!--标题、面包屑-->
<section class="content-header">
    <h1>
        设计室经理确认
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
        <li>设计室</li>
        <li>设计室任务</li>
        <li class="active">设计室经理确认</li>
    </ol>
</section>
<!--列表-->
<section class="content">

</section>
<!--添加、修改弹出层-->
<script type="text/template" data-for="tp_editor">
    <form role="form" class="form-horizontal">
        <div class="u-area">
            <div class="form-group">
                <label class="col-sm-2 control-label">编号：<%=data.p1?data.p1:''%></label>
                <div class="col-sm-4">
                    <input type="text" class="form-control"
                           value="<%=data.p1?data.p1:''%>" disabled>
                </div>

                <label class="col-sm-2 control-label">状态</label>
                <div class="col-sm-4">
                    <select class="form-control" name="p2">
                        <option>草稿</option>
                        <option>待采购部经理审核</option>
                        <option>制作中</option>
                        <option>待确认</option>
                        <option>已完成</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="u-box">
            <div class="u-box-header">
                <h3>操作人信息</h3>
            </div>
            <div class="u-area">
                <div class="form-group">
                    <label class="col-sm-2 control-label">申请人</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" name="p3"
                               value="<%=data.p3?data.p3:''%>">
                    </div>

                    <label class="col-sm-2 control-label">当前时间</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" name="p4"
                               value="<%=data.p4?data.p4:''%>">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">所属部门</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" name="p3"
                               value="<%=data.p3?data.p3:''%>">
                    </div>

                    <label class="col-sm-2 control-label">联系方式</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" name="p4"
                               value="<%=data.p4?data.p4:''%>">
                    </div>
                </div>
            </div>
        </div>
        <div class="u-box ">
            <div class="u-box-header ">
                <h3>设计内容</h3>
            </div>
            <div class="u-area">
                <div class="form-group">
                    <label class="col-sm-2 control-label">设计内容</label>
                    <div class="col-sm-10">
                        <textarea class="form-control" name="p18" disabled>
                               <%=data.p18?data.p18:''%></textarea>
                    </div>
                </div>
            </div>
        </div>
        <div class="u-box ">
            <div class="u-box-header ">
                <h3>设计部门经理确认</h3>
            </div>
            <div class="u-area">
                <div class="form-group">
                    <label class="col-sm-2 control-label">确认结果</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" name="p3"
                               value="<%=data.p3?data.p3:''%>">
                    </div>

                    <label class="col-sm-2 control-label">执行人</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" name="p4" data-action="taskUser"
                               value="<%=data.p4?data.p4:''%>">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">备注</label>
                    <div class="col-sm-10">
                        <textarea class="form-control" name="p18" >
                               <%=data.p18?data.p18:''%></textarea>
                    </div>
                </div>
            </div>
        </div>
        <div class="box-footer">
            <button type="submit" class="btn btn-primary pull-right">确定</button>
        </div>
    </form>
</script>

<script type="text/template" data-for="tp_editorUserTree">
    <form role="form" class="form-horizontal">
        <div class="box-body">
            <div class="form-group">
                <div class="col-sm-12">
                    <input type="text" class="form-control usersTreeSearch">

                    <div class="usersTree"></div>
                </div>
            </div>
        </div>
    </form>
</script>

<script>
    USEN(function () {
        //模块ID(全系统唯一)
        var tableId = "#sjs_shejishirenwu";
        var id = "#sjs_shejishirenwu_managerConfirm";

        //定义页面变量
        var $el = $(id);
        var $editor = $el.children('script[data-for=tp_editor]');
        var $tree = $el.children('script[data-for=tp_editorUserTree]');

        $.ajax({
            url:"./simdata/common_add_action.json",
            success:function(data){
                $el.children(".content").html(function(){
                    return _.template($editor.html())({
                        data:data
                    })
                });

                //提交表单
                $el.find("form").ajaxForm({
                    url: './simdata/common_add_action.json',
                    beforeSubmit: function (data) {
                        //console.log("数据提交之前.")
                    },
                    success: function (data, state, obj) {
                        USEN.notifyAlert({
                            title: "提示:",
                            content: '操作成功,刷新列表'
                        });
                        USEN.getDatatable(tableId + ' table.table').ajax.reload();
                        USEN.closeActiveTab();
                    }
                });

                $el.find("[data-action=taskUser]").on('click',function(){
                    var selected = null;
                    //绑定执行人弹出层事件
                    USEN.modal({
                        title:"请选择执行人",
                        success:function(){
                            $(this).find("select").width("98%").select2({
                                dropdownParent:$(this)
                            });

                            //初始化用户树结构
                            var userTree = $(this).find(".usersTree").on("changed.jstree", function (e, data) {
                                if (data.selected.length) {
                                    switch (data.action) {
                                        case 'ready' :
                                        case 'select_node' :
                                            if(data.node.type == 'default'){
                                                selected = data.node.text;
                                            }else{
                                                selected = null;
                                            }
                                            break;
                                    }
                                }
                            }).jstree({
                                'core': {
                                    'themes': {
                                        'name': 'proton',
                                        'responsive': true
                                    },
                                    data: {
                                        url: "./simdata/common_users_tree_action.json",
                                        dataType: "json"
                                    }
                                },
                                "plugins": [ "wholerow" , "types" , "search"],
                                "types": {
                                    "default": {
                                        "icon": "glyphicon glyphicon-user"
                                    },
                                    "org": {
                                        "icon": "glyphicon glyphicon-leaf"
                                    }
                                }
                            });

                            //绑定搜索框事件
                            $(this).find(".usersTreeSearch").on("input propertychange", function () {
                                userTree.jstree(true).search($(this).val());
                            });
                        },
                        submitTxt:"确定",
                        submitCb:function($modal){
                            if(!selected){
                                USEN.notifyAlert({
                                    title:"提示:",
                                    type:"fail",
                                    content:'请选择执行人'
                                });
                                return;
                            }
                            $el.find("[data-action=taskUser]").val(selected);
                            $modal.modal("hide");
                        },
                        filter:function(data){
                            return _.template($tree.html())({
                                data:data
                            });
                        }
                    });
                });


                $el.find("select").css('width','98%').select2({
                    dropdownParent:$el
                });
                $el.find("input[data-plugin=date]").datepicker({
                    autoclose: true
                })
            }
        })

    });
</script>
</div>